﻿@model Telerik.Web.Mvc.GridModel<HolidayDateModel>
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    //page title
    ViewBag.Title = T("Admin.Configuration.Holidays").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/subsites/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.Configuration.Holidays") @Html.ActionLink("(" + T("Admin.Common.List") + ")", "List")
    </div>
</div>

<table class="adminContent">
    <tr>
        <td>
            @ViewBag.HolidayName
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid(Model.Data)
                    .Name("dates-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                        x.Add(y => y.HolidayId).RouteKey("holidayId");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Id).Hidden();
                        columns.Bound(x => x.Date)
                            .EditorTemplateName("Date")
                            .Template(x => x.DateStr)
                            .ClientTemplate("<#= DateStr #>")
                            .Width(100);
                        columns.Command(commands =>
                        {
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                        }).Width(90);
                    })
                    .ToolBar(x => x.Insert())
                    .Pageable(settings => settings.PageSize(gridPageSize).Total(Model.Total).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("Dates", "Holiday")
                            .Delete("DateDelete", "Holiday", new { holidayId = ViewBag.HolidayId })
                            .Insert("DateAdd", "Holiday", new { id = 0, holidayId = ViewBag.HolidayId })
                            .Update("DateEdit", "Holiday");
                    })
                    .EnableCustomBinding(true)
                    .ClientEvents(x => x.OnError("Grid_onError"))
                    )
        </td>
    </tr>
</table>
<script type="text/javascript">
    function Grid_onError(e) {
        alert(e.XMLHttpRequest.responseText);
        e.preventDefault();
    }
</script>
